/*
 DNN Content Builder - sourceforge.net/projects/dnncb
 Copyright (c) 2004-2008
 by Emerson Lopes (emersonlopes@gmail.com)

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Collections;
using System.Data;
using System.ComponentModel;

namespace DNNContentBuilder 
{
	[Serializable]
	public class MetaDataTaskInfo 
	{
		// Entity member variables for database table epMetaDataTask
        
		private Int32		mMetaDataTaskId;
		private Int32		mTaskOrder;
		private DateTime	mStartDate;
		private string		mStatus;
		private string		mTitle;
		private DateTime	mFinishDate;
		private Int32		mMetaDataId;
		private string      mCreatedBy;
		private string      mContentType;
		private string      mContentTitle;

        
		// Calculated Expression member variables for database table epMetaDataTask
        
        
		// Entity properties for database table epMetaDataTask
        
		public Int32 MetaDataId 
		{
			get { return mMetaDataId; }
			set { mMetaDataId = value; }
		}

		public Int32 MetaDataTaskId 
		{
			get { return mMetaDataTaskId; }
			set { mMetaDataTaskId = value; }
		}

		public Int32 TaskOrder 
		{
			get { return mTaskOrder; }
			set { mTaskOrder = value; }
		}
        
        
		public DateTime StartDate 
		{
			get { return mStartDate; }
			set { mStartDate = value; }
		}
        
		public string Title 
		{
			get { return mTitle; }
			set { mTitle = value; }
		}

		public string CreatedBy 
		{
			get { return mCreatedBy; }
			set { mCreatedBy = value; }
		}

		public string ContentType 
		{
			get { return mContentType; }
			set { mContentType = value; }
		}

		public DateTime FinishDate 
		{
			get { return mFinishDate; }
			set { mFinishDate = value; }
		}
		
		public TaskStatus Status 
		{
			get
			{
				return (TaskStatus)TypeDescriptor.GetConverter(typeof(TaskStatus)).ConvertFromString(mStatus);
			}
			set
			{
				mStatus = TypeDescriptor.GetConverter(typeof(TaskStatus)).ConvertToString(value);
			}
		}

		public string ContentTitle
		{
			get { return mContentTitle; }
			set { mContentTitle = value; }
		}

		public string InternalStatus 
		{
			get { return mStatus; }
			set { mStatus = value; }
		}
	}
    
	public class MetaDataTaskController : BaseController
	{
		public MetaDataTaskController() : base() {}
		public MetaDataTaskController(ConnectionProvider cp) : base(cp) {}
        
		public Int32 Add(MetaDataTaskInfo MetaDataTaskInfo) 
		{
			return (Int32) base.GetDataProvider().MetaDataTaskAdd(MetaDataTaskInfo.TaskOrder, MetaDataTaskInfo.StartDate, MetaDataTaskInfo.InternalStatus, MetaDataTaskInfo.Title, MetaDataTaskInfo.FinishDate, MetaDataTaskInfo.MetaDataId);
		}
        
		public void Update(MetaDataTaskInfo MetaDataTaskInfo) 
		{
			base.GetDataProvider().MetaDataTaskUpdate(MetaDataTaskInfo.MetaDataTaskId, MetaDataTaskInfo.TaskOrder, MetaDataTaskInfo.StartDate, MetaDataTaskInfo.InternalStatus, MetaDataTaskInfo.Title, MetaDataTaskInfo.FinishDate, MetaDataTaskInfo.MetaDataId);
		}
        
		public void DeleteAll(Int32 metaDataId) {
			base.GetDataProvider().MetaDataTaskDeleteAll(metaDataId);
		}

		public void Delete(Int32 metaDataTaskId) 
		{
			base.GetDataProvider().MetaDataTaskDelete(metaDataTaskId);
		}
        
		public MetaDataTaskInfo GetItem(Int32 metaDataTaskId) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskGet(metaDataTaskId))
			{
				MetaDataTaskInfo infoObject = (MetaDataTaskInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(MetaDataTaskInfo));
				return infoObject;
			} 
		}
        
		// Select query methods for database table epMetaDataTask
		public ArrayList TasksByOwnerAndModule(Int32 taskOwnerId, Int32 moduleId) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskGetMetaDataTasksByOwnerAndModule(taskOwnerId, moduleId))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataTaskInfo));
				return infoList;
			} 
		}

		// open tasks of logged in user
		public ArrayList GetMetaDataTasksByOwner(Int32 TaskOwnerId) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskGetMetaDataTasksByOwner(TaskOwnerId))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataTaskInfo));
				return infoList;
			} 
		}
        
		// Relation methods for database table epMetaDataTask
		public ArrayList GetByTaskOwner(Int32 taskOwnerId) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskByTaskOwner(taskOwnerId))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataTaskInfo));
				return infoList;
			} 
		}

		//Get next task (if any) available task
		public MetaDataTaskInfo GetNextTask(Int32 metaDataId, Int32 taskOrder)
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskGetNext(metaDataId, taskOrder))
			{
				MetaDataTaskInfo infoObject = (MetaDataTaskInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(MetaDataTaskInfo));
				return infoObject;
			} 
		}
		
		public MetaDataTaskInfo GetCurrentTask(Int32 metaDataId) {
			using (IDataReader idr = base.GetDataProvider().MetaDataTaskGetCurrent(metaDataId))
			{
				MetaDataTaskInfo infoObject = (MetaDataTaskInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(MetaDataTaskInfo));

				return infoObject;
			} 
		}
	}
}
